<?php
/**
 * Created by JetBrains PhpStorm.
 * User: dodasso
 * Date: 7/29/13
 * Time: 9:04 PM
 * To change this template use File | Settings | File Templates.
 */

define('APP_ROOT', realpath(__DIR__ . '/../../..'));

require_once(APP_ROOT . '/ext/smarty/Smarty.class.php');
require_once(APP_ROOT . '/modules/persistance/DBConnector.php');
require_once(APP_ROOT . '/modules/log/log.php');
require_once(APP_ROOT . '/modules/log/logCommon.php');
require_once(APP_ROOT . '/modules/common/Errors.php');
require_once(APP_ROOT . '/modules/common/Common.php');

use persistance\DBConnector;
use log\Log;
use log\LogCommon;
use common\Errors;
use common\Common;

// Global.
$g_smarty = new Smarty();

function processGet() {
    global $g_smarty;

    Log::LOG_WEBROOTHTML_FB();

    // Check session.
    if(false) {
        Log::LOG_WEBROOTHTML(LogCommon::logTypeError, "Php session not valid.");
        header('Location: /html/login/login.php');
        return;
    }

    $g_smarty->display('index.tpl');

    Log::LOG_WEBROOTHTML_FE();
}

function main() {
    global $g_smarty;

    Log::LOG_WEBROOTHTML_FB();

    if($_SERVER['REQUEST_METHOD'] !== 'GET') {
        Log::LOG_WEBROOTHTML(LogCommon::logTypeError, "Invalid request method.");
        header('HTTP/1.1 400 Bad Request', true, 400);
        return;
    }

    $g_smarty->setTemplateDir(array(APP_ROOT . '/webroot/html/common/templates',
        APP_ROOT . '/webroot/html/inventory/templates'));
    $g_smarty->setCompileDir(APP_ROOT . '/cache/html/templates/compiled');
    $g_smarty->setCacheDir(APP_ROOT . '/cache/html/templates/cache');

    processGet();

    Log::LOG_WEBROOTHTML_FE();

    exit;
}

main();
